package com.pj.project.api_alioss;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.pj.three.ali_oss.AliOssUtil;
import com.pj.utils.sg.AjaxJson;

@RestController
@RequestMapping("/alioss/")
public class AliOssController {

	

	/** 
	 * @api {get} /alioss/getSign 获取oss授权签名  
	 * @apiGroup 其它-oss文件上传
	 * @apiParam ext=png 		文件后缀 
	 * @apiParam way=1 			上传类型（1=图片，2=视频，3=音频，11=pdf, 12=apk安装包 ） 
	 * @apiSuccessExample 成功返回示例 
		 {
		    "code": 200,
		    "msg": "ok",
		    "data": {
		        "file_url": "https://oss.dev33.cn/dyc/img/2020/03/23/15848961872811421064428.png",	// 文件最终地址 
		        "file_url_handle": "xxx?a=1",
		        "file_url_not_handle": "xxx",
		        "OSSAccessKeyId": "LTAI4FmGy72kkC8VVuQrBp4X",		// oss id
		        "x-oss-object-acl": "public-read",				// 文件读写权限
		        "success_action_status": 200,					// 上传成功返回的状态码 
		        "Signature": "URq26mqY4oOY48Dh8STalX3WpJA=",	// 签名
		        "host": "http://dev33-test.oss-cn-beijing.aliyuncs.com",	// host地址
		        "key": "dyc/img/2020/03/23/15848961872811421064428.png",	// 文件key，即：上传目录
		        "max_size": 104857600,										// 文件最大大小
		        "ext_list": "jpg,jpeg,png,gif,ico,bmp,tiff,raw",			// 允许的文件后缀集合 
		        "policy": "eyJleHBpcmF0aW9uIjoiMjAyMC0wMy0yMlQxNzowMToyNy43MDJaIiwiY29uZGl0aW9ucyI6W1siY29udGVudC1sZW5ndGgtcmFuZ2UiLDAsMTA0ODU3NjAwXSxbInN0YXJ0cy13aXRoIiwiJGtleSIsImR5Yy9pbWcvMjAyMC8wMy8yMy8xNTg0ODk2MTg3MjgxMTQyMTA2NDQyOC5wbmciXV19"
		    },
		    "dataCount": null
		}
	 */
	// 获得oss签名等信息
	// way=方式 1=图片，2=视频，3=音频，11=pdf, 12=apk安装包 
	@RequestMapping(value="getSign")
	public AjaxJson getSign(HttpServletRequest request, String ext, @RequestParam(defaultValue="1")int way){
//		StpUtil.getLoginId();
//		if(StpUtil.getLoginId(0) == 0 && StpUserUtil.getLoginId(0) == 0) {
//			throw new NotLoginException();
//		}
		Map<String, Object> map = AliOssUtil.getSignInfo(ext, way);
		// 是否添加水印  
//		if(SysCfgUtil.get_upload_sy()) {
//			map.put("file_url", map.get("file_url_handle"));
//		} else {
//			map.put("file_url", map.get("file_url_not_handle"));
//		}

		map.put("file_url", map.get("file_url_handle"));
		return AjaxJson.getSuccessData(map);
	}
	
	
	
	
	
	
}
